/**
 * ProductComeoutItemServiceImpl.java
 * @author
 * 作者 屈甲康 
 */
package org.jackysoft.service.impl;

import java.util.Collection;
import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jackysoft.entity.ProductComeoutItem;
import org.jackysoft.service.AbstractStringIdServiceImpl;
import org.jackysoft.service.ContractService;
import org.jackysoft.service.ProductComeoutItemService;
import org.joda.time.DateTime;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;


@Service
@Transactional
public class ProductComeoutItemServiceImpl extends AbstractStringIdServiceImpl<ProductComeoutItem>
implements ProductComeoutItemService {
    /**
	 * 
	 */
	private static final long serialVersionUID = -4217439689114962920L;
	final static Log logger = LogFactory.getLog(ProductComeoutItemServiceImpl.class);
    private ContractService contService;
	public ProductComeoutItemServiceImpl(){
	    super(ProductComeoutItem.class);
	}

	
	
	
	@Override
	@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)
	public void create(Collection<ProductComeoutItem> bs)
			throws DataAccessException {
		
		super.create(bs);
		
		
		
	}
	
	void afterBatchCreation(Collection<ProductComeoutItem> bs){
		for(ProductComeoutItem bean : bs){
			contService.updateStorage(bean.getContract(), bean.getProduct(), bean.getValue());
		}
		
	}




	@SuppressWarnings({ "unchecked", "rawtypes" })
	@Override
	public Collection<ProductComeoutItem> findAll(String client, DateTime dt) {
		String hql=HQL("from %s t where datediff(date(t.fireDate),date('%s'))=0 and  t.contract.client.id='%s'"
				,table(),dt.toString("yyyy-MM-dd"),client
				);
		List list = query(hql).list();
		return list;
	}

	@Resource
    public void setContService(ContractService contService) {
		this.contService = contService;
	}	
		
}